package com.ltkj.shop.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.ltkj.common.core.utils.DateUtils;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.datascope.annotation.DataScope;
import com.ltkj.common.security.utils.SecurityUtils;
import com.ltkj.shop.domain.ShopRestaurant;
import com.ltkj.shop.domain.vo.ShopRestMenuVo;
import com.ltkj.shop.mapper.ShopRestaurantMapper;
import com.ltkj.shop.mapper.ShopRestaurantMenuBizMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ltkj.shop.mapper.ShopRestaurantMenuMapper;
import com.ltkj.shop.domain.ShopRestaurantMenu;
import com.ltkj.shop.service.IShopRestaurantMenuService;

/**
 * 餐饮菜品Service业务层处理
 * 
 * @author xupf
 * @date 2023-08-29
 */
@Service
public class ShopRestaurantMenuServiceImpl implements IShopRestaurantMenuService 
{
    @Autowired
    private ShopRestaurantMenuMapper shopRestaurantMenuMapper;
    @Autowired
    private ShopRestaurantMapper shopRestaurantMapper;
    @Autowired
    private ShopRestaurantMenuBizMapper shopRestaurantMenuBizMapper;

    /**
     * 查询餐饮菜品
     * 
     * @param id 餐饮菜品主键
     * @return 餐饮菜品
     */
    @Override
    public ShopRestMenuVo selectShopRestaurantMenuById(Long id)
    {
        return shopRestaurantMenuBizMapper.selectShopRestaurantMenuById(id);
    }

    /**
     * 查询餐饮菜品列表
     * 
     * @param shopRestaurantMenu 餐饮菜品
     * @return 餐饮菜品
     */
    @Override
    @DataScope(storeAlias = "rm")
    public List<ShopRestaurantMenu> selectShopRestaurantMenuList(ShopRestaurantMenu shopRestaurantMenu)
    {
        return shopRestaurantMenuBizMapper.selectShopRestaurantMenuList(shopRestaurantMenu);
    }

    /**
     * 移动端查询餐饮菜品列表
     *
     * @param shopRestaurantMenu 餐饮菜品
     * @return 餐饮菜品
     */
    @Override
    public List<ShopRestaurantMenu> selectList(ShopRestaurantMenu shopRestaurantMenu)
    {
        return shopRestaurantMenuBizMapper.selectList(shopRestaurantMenu);
    }

    /**
     * 新增餐饮菜品
     * 
     * @param shopRestaurantMenu 餐饮菜品
     * @return 结果
     */
    @Override
    public AjaxResult insertShopRestaurantMenu(ShopRestaurantMenu shopRestaurantMenu)
    {
        ShopRestaurant shopRestaurant = shopRestaurantMapper.selectShopRestaurantById(shopRestaurantMenu.getRestaurantId());
        shopRestaurantMenu.setSysStoresId(shopRestaurant.getSysStoresId());
        shopRestaurantMenu.setCreateTime(DateUtils.getNowDate());
        shopRestaurantMenu.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        shopRestaurantMenu.setUserId(SecurityUtils.getLoginUser().getUserid());
        shopRestaurantMenu.setIsDel("0");

        // 转换金额 元 -> 分
        shopRestaurantMenu.setPrice(shopRestaurantMenu.getPrice().multiply(new BigDecimal(100)));
        shopRestaurantMenu.setVipPrice(shopRestaurantMenu.getVipPrice().multiply(new BigDecimal(100)));

        int i;
        try {
            i = shopRestaurantMenuMapper.insertShopRestaurantMenu(shopRestaurantMenu);
        } catch (Exception e) {
            return AjaxResult.error();
        }
        if (i > 0) {
            return AjaxResult.success(shopRestaurantMenu);
        } else {
            return AjaxResult.error();
        }
    }

    /**
     * 修改餐饮菜品
     * 
     * @param shopRestaurantMenu 餐饮菜品
     * @return 结果
     */
    @Override
    public int updateShopRestaurantMenu(ShopRestaurantMenu shopRestaurantMenu)
    {
        shopRestaurantMenu.setUpdateTime(DateUtils.getNowDate());
        shopRestaurantMenu.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        // 转换金额 元 -> 分
        shopRestaurantMenu.setPrice(shopRestaurantMenu.getPrice().multiply(new BigDecimal(100)));
        shopRestaurantMenu.setVipPrice(shopRestaurantMenu.getVipPrice().multiply(new BigDecimal(100)));
        return shopRestaurantMenuMapper.updateShopRestaurantMenu(shopRestaurantMenu);
    }

    /**
     * 批量删除餐饮菜品
     * 
     * @param ids 需要删除的餐饮菜品主键
     * @return 结果
     */
    @Override
    public int deleteShopRestaurantMenuByIds(Long[] ids)
    {
        return shopRestaurantMenuBizMapper.deleteShopRestaurantMenuByIds(ids);
    }

    /**
     * 删除餐饮菜品信息
     * 
     * @param id 餐饮菜品主键
     * @return 结果
     */
    @Override
    public int deleteShopRestaurantMenuById(Long id)
    {
        return shopRestaurantMenuBizMapper.deleteShopRestaurantMenuById(id);
    }
}
